-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export build time not found packages on runtime #518
Conversation
Exporting eval results
8f3345e
to
840c68e
Compare
@@ -1 +1 @@ | |||
__non_webpack_require__('UNKNOWN'); | |||
module.exports = __non_webpack_require__('UNKNOWN'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are cases that the packages are missing at ncc build time, yet presented at global scope or runtime. Without this fix, the eval("require")('dep')
can succeed at runtime but the result is not exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are cases that the packages are missing at ncc build time, yet presented at global scope or runtime.
Which cases? Can you add a test that fails but succeeds with this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say we have a project referencing an optional dependency using
try {
foo = require('foo');
} catch {}
Package foo
is not installed on build time since it's totally optional and should not be bundled into the products. So package foo
will be transformed by loader runtime-notfound
to eval("require")("foo")
without assigning return value to module.exports
. Since then the require('foo')
can succeed without any error at runtime but the return value is undefined
, not the dynamically required package module.
The test case test/unit/runtime-notfound/output.js
is already presented in the repo, and is identical to the case above, which has been updated in the PR to reflect the correct result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I should have been more clear. Can you add an integration test that fails with the latest ncc but succeeds with this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integration test added, PTAL :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, it seems like this should have been exported from the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Exporting eval results.